<template>
  <div class="model-form">
    <el-page-header @back="goBack" content="增加会员">
    </el-page-header>
    <div class="model-content">
      <el-form ref="ruleForm" :rules="rules" :model="form" label-width="160px">
        <el-row :gutter="10">
          <el-col :span="22">
            <el-form-item label="姓名" size="mini" prop="name">
              <el-input v-model="form.name" name="name">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="照片" size="mini" prop="avatar">
              <avatar v-model="form.avatar"></avatar>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="电话" size="mini" prop="phone">
              <el-input v-model="form.phone" name="phone">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="性别" size="mini" prop="sex">
              <nb-select catalog="sex" v-model="form.sex"></nb-select>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="年龄" size="mini" prop="age">
              <el-input-number v-model="form.age" name="age" type="textarea" :min="0" :max="100"></el-input-number>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="身份证号" size="mini" prop="cardNo">
              <el-input v-model="form.cardNo" name="cardNo">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="现住址" size="mini" prop="address">
              <el-input v-model="form.address" name="address">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="毕业院校" size="mini" prop="school">
              <el-input v-model="form.school" name="school">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="身高" size="mini" prop="height">
              <el-input v-model="form.height" name="height">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="体重" size="mini" prop="weight">
              <el-input v-model="form.weight" name="weight">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="三围" size="mini" prop="threeLatitude">
              <el-input v-model="form.threeLatitude" name="threeLatitude">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="推荐人" size="mini" prop="recommender">
              <el-input v-model="form.recommender" name="recommender">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="报名费" size="mini" prop="fee">
              <el-input v-model="form.fee" name="fee">
              </el-input>
            </el-form-item>

          </el-col>

          <el-col :span="22">
            <el-form-item>
              <el-button @click="goBack">取消</el-button>
              <el-button type="primary" @click="add">确定</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
import common from "@/mixins/common.js";
import nbSelect from "@/components/nbSelect.vue";
import avatar from "@/components/avatar.vue";

export default {
  name: "model_add",
  mixins: [common],
  components: {nbSelect, avatar},
  data() {
    return {
      form: {
        name: '',
        avatar: '',
        phone: '',
        sex: '',
        age: '',
        cardNo: '',
        address: '',
        school: '',
        height: '',
        weight: '',
        threeLatitude: '',
        recommender: '',
        fee: ''
      },
      rules: {
        name: [
          {required: true, message: '请输入姓名', trigger: 'blur'}
        ],
        avatar: [
          {required: true, message: '请输入照片', trigger: 'blur'}
        ],
        phone: [
          {required: true, message: '请输入电话', trigger: 'blur'}
        ],
      }
    }
  },
  methods: {
    async add() {
      let valid = await this.$refs["ruleForm"].validate();
      if (!valid) {
        return false;
      }
      await this.addData();
    },
    async addData() {
      let data = this.form;
      let res = await this.$http.form("/tenantRest/model/create.htm", data);
      if (res.code !== 0) {
        this.$message.error(res.msg);
      }

      this.$message({
        message: '添加数据成功',
        type: 'success'
      });
      this.$router.go(-1);
    },

  },
  mounted() {
  }
}

</script>

<style scoped>
</style>
